package com.wz.project.tsjqueue.controller;

import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.ddjqueue.domain.WmsDeviceExecutionQueue;
import com.wz.project.ddjqueue.service.IWmsDeviceExecutionQueueService;
import com.wz.project.tsjqueue.domain.TsjExecutionQueue;
import com.wz.project.tsjqueue.service.TsjExecutionQueueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/device/tsjqueue")
public class TsjExecutionQueueController extends BaseController
{
    private String prefix = "device/tsjqueue";

    @Autowired
    private TsjExecutionQueueService tsjExecutionQueueService;

    @RequiresPermissions("device:tsjqueue:view")
    @GetMapping()
    public String tsjqueue()
    {
        return prefix + "/tsjqueue";
    }

    /**
     * 查询堆垛机执行队列列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TsjExecutionQueue tsjExecutionQueue)
    {
        startPage();
        List<TsjExecutionQueue> list = tsjExecutionQueueService.selectTsjExecutionQueueList(tsjExecutionQueue);
        return getDataTable(list);
    }


    /**
     * 重新下发堆垛机执行队列
     */
    @Log(title = "提升机执行队列", businessType = BusinessType.UPDATE)
    @RequestMapping("/reloadTask")
    @ResponseBody
    public AjaxResult reloadTask(TsjExecutionQueue queue){
        int sa = tsjExecutionQueueService.reloadTask(queue);
        if(sa == 1){
            return AjaxResult.success("重新下发成功！");
        }else{
            return AjaxResult.error("只有正执行的队列才可以重新下发！");
        }
    }

    /**
     * 删除堆垛机执行队列
     */
    @Log(title = "提升机执行队列", businessType = BusinessType.DELETE)
    @RequestMapping("/deleteTask")
    @ResponseBody
    public AjaxResult deleteTask(TsjExecutionQueue queue){
        int sa = tsjExecutionQueueService.deleteTask(queue);
        if(sa == 1){
            return AjaxResult.success("删除成功！");
        }else{
            return AjaxResult.error("只有正执行的队列才可以删除！");
        }
    }
}
